package com.ch.sys.utils;

import java.io.IOException;
import java.util.List;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.type.TypeReference;

public class JsonUtils
{
	private static JsonBinder binder = JsonBinder.buildNonDefaultBinder(); 
	
    public static <T> T toBean(String jsonString, Class<T> c) throws IOException
    { 
         return binder.getMapper().readValue(jsonString, c);
    }

    public static <T> List<T> toBeanList(String jsonString, Class<T> c) throws JsonParseException, JsonMappingException, IOException
    {
    	return binder.getMapper().readValue(jsonString, new TypeReference<List<T>>() {});   
    }

    public static <T> String toJson(T entity)
    {
        return binder.toJson(entity);
    }
} 

